package com.suguowen.sblog.mapper;

import com.suguowen.sblog.bean.Article;
import com.suguowen.sblog.bean.ArticleExample;
import java.util.List;

import org.apache.ibatis.annotations.*;
import org.mybatis.spring.support.SqlSessionDaoSupport;

public interface ArticleMapper {
    long countByExample(ArticleExample example);

    int deleteByExample(ArticleExample example);

    int deleteByPrimaryKey(Integer artId);

    int insert(Article record);

    @Insert("insert into article (title, update_time,create_time,user_id,tag_id) values(#{title},#{createTime},#{updateTime},#{userId},#{tagId})")
    @Options(useGeneratedKeys=true,keyProperty = "artId", keyColumn = "art_id")
    int insertArtReturnArtId(Article record);

    int insertSelective(Article record);

    List<Article> selectByExample(ArticleExample example);

    Article selectByPrimaryKey(Integer artId);

    int updateByExampleSelective(@Param("record") Article record, @Param("example") ArticleExample example);

    int updateByExample(@Param("record") Article record, @Param("example") ArticleExample example);

    int updateByPrimaryKeySelective(Article record);

    int updateByPrimaryKey(Article record);

    // 把文章标签设为未分类
    @Update("update article set tag_id = 999 where tag_id = #{tagId}")
    int updateTagNoneByArtId(Integer tagId);

    @Update("update article set reading_quantity = reading_quantity + 1 where art_id = #{artId}")
    int updateArticleReadingQuantity(Integer artId);

    // 日期分类
    @Select("SELECT DATE_FORMAT(create_time,'%Y-%m') weeks FROM article GROUP BY weeks")
    List<String> selectCreateTime();
}